<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="订单号">
              <a-input placeholder="请输入订单号" v-model="queryParam.orderCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="订单状态">
              <a-select placeholder="请选择订单状态" v-model="queryParam.retrunOrderCode">
                <a-select-option :value="value" :key="value" v-for="(key, value) in returnStatus">{{
                  key
                }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="时间范围">
              <a-range-picker
                style="width:100%"
                showToday
                format="YYYY-MM-DD"
                v-model="dates"
                :placeholder="['开始时间', '结束时间']"
                @change="handleTimeOk"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
<!--        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择-->
<!--        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a-->
<!--        >项-->
<!--        <a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
<!--      </div>-->

      <a-table
        ref="table"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
      <span slot="orderStatus"  slot-scope="orderStatus">
          <span>{{OrderStatus[orderStatus]}}</span>
      </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record,1)">详情</a>&emsp;
          <a v-if="record.orderStatus==='60'" @click="handleDetail(record,2)">发货</a>&emsp;
          <a v-if="record.orderStatus==='110'" @click="handleDetail(record,3)">审批</a>
        </span>
      </a-table>
    </div>

    <!-- 订单详情 -->
    <order-detail :visible="detailVisible" :id="detailId" :type="checkType" @refreshList="loadData" @onClose="()=>this.detailVisible=false"></order-detail>
  </a-card>
</template>

<script>
import { getAction } from '@/api/manage'
import OrderDMainModal from '@page-modules/OrderDMainModal'
import { PageListMixin } from '@/mixins/PageListMixin'
import JInput from '@/components/cn-form/JInput.vue'
import moment from 'moment'
import OrderDetail from './modules/OrderDetail.vue'
export default {
  name: 'order-list',
  mixins: [PageListMixin],
  components: {
    OrderDMainModal,
    JInput,
    OrderDetail
  },
  data() {
    const timeS = new Date()
    const timeE = new Date()
    timeS.setHours(0)
    timeS.setMinutes(0)
    timeS.setSeconds(0)
    timeE.setHours(23)
    timeE.setMinutes(59)
    timeE.setSeconds(59)

    return {
      returnStatus: {
        '110': '退款审批中',
        '120': '退款中',
        '130': '退款完成',
        '140': '退款驳回',
        '150': '退款失败'
      },
      dates: [],
      innerData: [],
      expandedRowKeys: [],
      id: ' ',
      description: '列表展开子表Demo',
      // 列表表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '订单编号',
          align: 'center',
          dataIndex: 'orderCode'
        },
        {
          title: '订单日期',
          align: 'center',
          dataIndex: 'createDate'
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'createName'
        },
        {
          title: '状态',
          align: 'center',
          key: 'orderStatus',
          dataIndex: 'orderStatus',
          scopedSlots: { customRender: 'orderStatus' }
        },
        // {
        //   title: '订单金额（元）',
        //   align: 'center',
        //   dataIndex: 'totalAmount'
        // },
        // {
        //   title: '手续费（元）',
        //   align: 'center',
        //   dataIndex: 'handlingFee'
        // },
        // {
        //   title: '佣金（元）',
        //   align: 'center',
        //   dataIndex: 'commission'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 分页参数
      type: 'radio',
      url: {
        list: window._CONFIG['domianOrderURL'] + '/order/flpReturnOrder/findReturnByCustPageList',
      },
      detailVisible: false,
      detailId: '',
      checkType: 1
    }
  },
  computed: {
    currentId() {
      return this.id
    }
  },
  methods: {
    moment,
    //查看详情
    handleDetail(record,type) {
      this.detailVisible = true
      this.detailId = record.id
      this.checkType = type
    },
    //开始时间结束时间
    handleTimeOk(date, dateStr) {
      console.log(date, dateStr)
      if (dateStr.length === 2) {
        this.queryParam.startDate = dateStr[0]
        this.queryParam.endDate = dateStr[1]
        this.dates = dateStr
      } else {
         this.queryParam.startDate = undefined
        this.queryParam.endDate = undefined
        this.dates = []
      }
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
.ant-card-body .table-operator {
  margin-bottom: 0px;
}

.ant-table-tbody .ant-table-row td {
  padding-top: 15px;
  padding-bottom: 15px;
}

.anty-row-operator button {
  margin: 0 5px;
}

.ant-btn-danger {
  background-color: #ffffff;
}

.ant-modal-cust-warp {
  height: 100%;
}

.ant-modal-cust-warp .ant-modal-body {
  height: calc(100% - 110px) !important;
  overflow-y: auto;
}

.ant-modal-cust-warp .ant-modal-content {
  height: 90% !important;
  overflow-y: hidden;
}
</style>
